package cn.ticket.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.ticket.dao.BusesMapper;
import cn.ticket.model.Buses;
import cn.ticket.model.Busorder;
import cn.ticket.service.BusOrderService;
import cn.ticket.service.BusesService;
@Service
public class BusesServiceImpl implements BusesService {

	@Autowired
	BusesMapper busesMapper;
	@Autowired 
	BusOrderService busOrderService;
	@Override
	public int deleteByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return busesMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(Buses record) {
		// TODO Auto-generated method stub
		return busesMapper.insert(record);
	}

	@Override
	public int insertSelective(Buses record) {
		// TODO Auto-generated method stub
		return busesMapper.insertSelective(record);
	}

	@Override
	public Buses selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return busesMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(Buses record) {
		// TODO Auto-generated method stub
		return busesMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(Buses record) {
		// TODO Auto-generated method stub
		return busesMapper.updateByPrimaryKey(record);
	}

	@Override
	public List<Buses> getAll() {
		// TODO Auto-generated method stub
		return busesMapper.getAll();
	}

	@Override
	public List<Buses> getByBusOrderId(int busOrderId) {
		// TODO Auto-generated method stub
		return busesMapper.getByBusOrderId(busOrderId);
	}

	@Override
	public List<Map<String, Object>> getInfo() {
		// TODO Auto-generated method stub
		return busesMapper.getInfo();
	}

	@Override
	public List<Map<String, Object>> getInfoByCount(int start, int count) {
		// TODO Auto-generated method stub
		return busesMapper.getInfoByCount(start, count);
	}

	@Override
	public List<Map<String, Object>> getInfoByBusOrderId(Integer busOrderIds) {
		// TODO Auto-generated method stub
		return busesMapper.getInfoByBusOrderId(busOrderIds);
	}

	@Override
	public int initialInsert0(int busorderId) {
		// TODO Auto-generated method stub
		Buses bus1=new Buses();
		bus1.setBusorderid(busorderId);
		bus1.setRouteid((short) 1);
		bus1.setNumber((byte) 1);
			
		Buses bus2=new Buses();
		bus2.setBusorderid(busorderId);
		bus2.setRouteid((short) 2);
		bus2.setNumber((byte) 2);
//		bus2.setSeatcount((short) );
		
		Buses bus3=new Buses();
		bus3.setBusorderid(busorderId);
		bus3.setRouteid((short) 3);
		bus3.setNumber((byte) 3);
		
		Buses bus4=new Buses();
		bus4.setBusorderid(busorderId);
		bus4.setRouteid((short) 4);
		bus4.setNumber((byte) 4);
		
		Buses bus5=new Buses();
		bus5.setBusorderid(busorderId);
		bus5.setRouteid((short) 4);
		bus5.setNumber((byte) 5);
		

		
//		Buses bus6=new Buses();
//		bus6.setBusorderid(busorderId);
//		bus6.setRouteid((short) 2);
//		bus6.setNumber((byte) 8);
//		bus6.setSeatcount((short) 13);
		
		int num1=busesMapper.insertSelective(bus1);
		int num2=busesMapper.insertSelective(bus2);
		int num3=busesMapper.insertSelective(bus3);
		int num4=busesMapper.insertSelective(bus4);
		int num5=busesMapper.insertSelective(bus5);
	//	int num6=busesMapper.insertSelective(bus6);
		return num1+num2+num3+num4+num5;
	}

	@Override
	public int initialInsert1(int busorderId) {
		// TODO Auto-generated method stub
		Buses bus1=new Buses();
		bus1.setBusorderid(busorderId);
		bus1.setRouteid((short) 5);
		bus1.setNumber((byte) 1);				
		
		Buses bus2=new Buses();
		bus2.setBusorderid(busorderId);
		bus2.setRouteid((short) 6);
		bus2.setNumber((byte) 2);
	//	bus2.setSeatcount((short) 47);
		
//		Buses bus6=new Buses();
//		bus6.setBusorderid(busorderId);
//		bus6.setRouteid((short) 6);
//		bus6.setNumber((byte) 3);
//		bus6.setSeatcount((short) 13);
		
		Buses bus3=new Buses();
		bus3.setBusorderid(busorderId);
		bus3.setRouteid((short) 7);
		bus3.setNumber((byte) 3);
		
		Buses bus4=new Buses();
		bus4.setBusorderid(busorderId);
		bus4.setRouteid((short) 8);
		bus4.setNumber((byte) 4);
		
		Buses bus5=new Buses();
		bus5.setBusorderid(busorderId);
		bus5.setRouteid((short) 9);
		bus5.setNumber((byte) 5);

		
		int num1=busesMapper.insertSelective(bus1);
		int num2=busesMapper.insertSelective(bus2);
		int num3=busesMapper.insertSelective(bus3);
		int num4=busesMapper.insertSelective(bus4);
		int num5=busesMapper.insertSelective(bus5);
	//	int num6=busesMapper.insertSelective(bus6);
	//	return num1+num2+num3+num4+num5+num6;
		return num1+num2+num3+num4+num5;
	}

	@Override
	public List<Map<String, Object>> getNearestBuses0() {
		// TODO Auto-generated method stub
		List<Busorder> busorders = busOrderService.getValideOrder0();
		if (busorders.isEmpty()) {
			return null;
		}
		return busesMapper.getInfoByBusOrderId(busorders.get(0).getId());
	}

	@Override
	public List<Map<String, Object>> getNearestBuses1() {
		// TODO Auto-generated method stub
		List<Busorder> busorders = busOrderService.getValideOrder1();
		if (busorders.isEmpty()) {
			return null;
		}
		return busesMapper.getInfoByBusOrderId(busorders.get(0).getId());
	}

	@Override
	public List<Buses> getByBusorderidAndRouteid(int busOrderId, Byte routeId) {
		// TODO Auto-generated method stub
		return busesMapper.getByBusorderidAndRouteid(busOrderId, routeId);
	}

	@Override
	public int seatOccupationRemove1(int id) {
		// TODO Auto-generated method stub
		return busesMapper.seatOccupationRemove1(id);
	}

	@Override
	public int seatOccupationAdd1(int id) {
		// TODO Auto-generated method stub
		return busesMapper.seatOccupationAdd1(id);
	}



}
